﻿using System.Collections.Generic;

namespace FileZillaConfig.ConfigClasses
{
    public class Passive
    {
        private int _rangePortMin;
        private int _rangePortMax;
        private string _externalIPServer = "http://ip.filezilla-project.org/ip.php";
        private bool _useCustomPortRange;
        private bool _noExternalIPLocal = true;
        private string _customIP;
        private IPMode _customIPMode;

        /// <summary>
        /// IP mode 
        /// </summary>
        public IPMode CustomIPMode
        {
            get { return _customIPMode; }
            set { _customIPMode = value; }
        }


        /// <summary>
        /// Use the following IP
        /// </summary>
        public string CustomIP
        {
            get { return _customIP; }
            set { _customIP = value; }
        }


        /// <summary>
        /// Don't use external IP for local connections
        /// </summary>
        public bool NoExternalIPOnLocal
        {
            get { return _noExternalIPLocal; }
            set { _noExternalIPLocal = value; }
        }


        /// <summary>
        /// Use custom port range
        /// </summary>
        public bool UseCustomPortRange
        {
            get { return _useCustomPortRange; }
            set { _useCustomPortRange = value; }
        }


        /// <summary>
        /// Retrieve external IP from
        /// </summary>
        public string ExternalIPServer
        {
            get { return _externalIPServer; }
            set { _externalIPServer = value; }
        }


        /// <summary>
        /// Passive mode port range. First value has to be lower then or equal to the second one.
        /// </summary>
        /// <param name="min">Minimum port number. Integer between 1 and 65535</param>
        /// <param name="max">Maximum port number. Integer between 1 and 65535</param>
        public void setPortRange(int min, int max)
        {
            if ((min >= 1 && min <= 65535) && (max >= 1 && max <= 65535) && (min <= max))
            {
                this._rangePortMax = max;
                this._rangePortMin = min;
            }
            else
            {
                throw new System.Exception("Value must be integer between 1 and 65535. Also first value has to be lower then or equal to the second one.");
            }
        }

        public Dictionary<string, int> getPortRange()
        {
            Dictionary<string, int> range = new Dictionary<string, int>();
            range["min"] = this._rangePortMin;
            range["max"] = this._rangePortMax;

            return range;
        }

    }
}
